using System.Linq;
using UnityEngine;
using UnityEngine.UI;

namespace MaterialUI
{
	public class ButtonRectInstantiationHelper : InstantiationHelper
	{
		public const int optionRaised = 0;

		public const int optionHasDropdown = 1;

		public const int optionHasContent = 2;

		[SerializeField]
		private MaterialButton m_Button;

		[SerializeField]
		private MaterialDropdown m_Dropdown;

		[SerializeField]
		private RectTransform m_RectTransform;

		[SerializeField]
		private HorizontalLayoutGroup m_Content;

		[SerializeField]
		private RectTransform m_Text;

		[SerializeField]
		private Graphic m_Icon;

		[SerializeField]
		private VectorImageData m_IconData;

		public override void HelpInstantiate(int[] options)
		{
			m_Button.isCircularButton = false;
			if (!options.Contains(0))
			{
				m_Button.isRaisedButton = true;
				m_Button.Convert(noExitGUI: true);
			}
			else
			{
				m_Button.isRaisedButton = true;
			}
			if (!options.Contains(1))
			{
				UnityEngine.Object.DestroyImmediate(m_Dropdown);
				m_Button.buttonObject.onClick = null;
				m_Icon.rectTransform.SetAsFirstSibling();
				m_Icon.SetImage(m_IconData);
				RectOffset padding = m_Content.padding;
				padding.right = 0;
				m_Content.padding = padding;
				m_Button.text.text = "BUTTON";
			}
			else
			{
				m_Button.icon = null;
				m_Button.fitWidthToContent = false;
				m_Content.childAlignment = TextAnchor.MiddleLeft;
				m_Content.padding.top = 0;
				m_Content.padding.bottom = 0;
				RectTransform rectTransform = (RectTransform)m_Content.transform;
				RectTransform rectTransform2 = rectTransform;
				Vector2 sizeDelta = rectTransform.sizeDelta;
				rectTransform2.sizeDelta = new Vector2(-30f, sizeDelta.y);
				RectTransform rectTransform3 = rectTransform;
				Vector2 anchoredPosition = rectTransform.anchoredPosition;
				rectTransform3.anchoredPosition = new Vector2(0f, anchoredPosition.y);
				RectTransform rectTransform4 = m_Button.rectTransform;
				Vector2 sizeDelta2 = m_Button.rectTransform.sizeDelta;
				rectTransform4.sizeDelta = new Vector2(134f, sizeDelta2.y);
				m_Icon.gameObject.AddComponent<LayoutElement>().ignoreLayout = true;
				m_Icon.rectTransform.anchorMin = new Vector2(1f, 0.5f);
				m_Icon.rectTransform.anchorMax = new Vector2(1f, 0.5f);
				m_Icon.rectTransform.anchoredPosition = new Vector2(-12f, 0f);
				m_Icon.rectTransform.sizeDelta = new Vector2(24f, 24f);
				base.gameObject.AddComponent<LayoutElement>().preferredWidth = 134f;
			}
			if (!options.Contains(2))
			{
				m_Button.contentRectTransform = m_Text;
				m_Text.SetParentAndScale(m_RectTransform, m_Text.localScale);
				m_Text.anchorMin = Vector2.zero;
				m_Text.anchorMax = Vector2.one;
				UnityEngine.Object.DestroyImmediate(m_Content.gameObject);
				m_Button.icon = null;
				m_Button.SetLayoutDirty();
			}
			base.HelpInstantiate(options);
		}
	}
}
